package com.simple.piger.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class BaseController extends AbstractController {

    @Autowired
    public HttpServletResponse response;
    public HttpServletRequest getRequest() {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        return request;
    }

    protected HttpSession getSession() {
        return getRequest().getSession();
    }

    protected void setAttribute(String key, String value) {
        getSession().setAttribute(key, value);
    }

    protected String getValueFromSession(String key) {
        Object o = getSession().getAttribute(key);
        return o == null ? null : o.toString();
    }
}